package com.wtb.javatool.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wtb.javatool.common.PageResult;
import com.wtb.javatool.dao.TeacherApplyMapper;
import com.wtb.javatool.entity.TeacherApply;
import com.wtb.javatool.service.ITeacherApplyService;
import com.wtb.javatool.vo.TeacherApplyDto;
import com.wtb.javatool.vo.TeacherApplyRecordPageDto;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class TeacherApplyService implements ITeacherApplyService {

    @Autowired
    private TeacherApplyMapper teacherApplyMapper;

    public void newApply(TeacherApplyDto teacherApplyDTO) {
        TeacherApply teacherApply = new TeacherApply();
        BeanUtils.copyProperties(teacherApplyDTO, teacherApply);
        teacherApply.setApply_time(LocalDateTime.now());
        teacherApply.setApproverId("1");
        teacherApply.setStatus("1");
        teacherApplyMapper.insert(teacherApply);

    }

    public PageResult teacherApplyRecordpageQuery(TeacherApplyRecordPageDto teacherApplyRecordPageDTO) {
        PageHelper.startPage(teacherApplyRecordPageDTO.getPageNum(), teacherApplyRecordPageDTO.getPageSize());
        Page<TeacherApply> page = teacherApplyMapper.teacherApplyRecordpageQuery(teacherApplyRecordPageDTO);
        long total = page.getTotal();
        List<TeacherApply> result = page.getResult();
        return new PageResult(total, result);
    }

    public PageResult teacherListPage(int pageNum, int pageSize, String name) {
        PageHelper.startPage(pageNum, pageSize);
        String status = "1";
        Page<TeacherApply> page = teacherApplyMapper.teacherListPage(name, status);
        long total = page.getTotal();
        List<TeacherApply> result = page.getResult();
        return new PageResult(total, result);
    }
}
